from PyQt5.QtWidgets import *       #部件，控件相关
from PyQt5.QtGui import *           #图片相关
from PyQt5.QtCore import *          #事件相关(鼠标等事件)

import sys                          

from ui.Ui_Timer_01 import Ui_Form


#自定义窗口，继承窗口
class MyWidget(QWidget):
    
    def __init__(self, parent=None):
        super().__init__(parent)
        
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        
        
        self.init_ui()

    def init_ui(self):

        self.ui.start_Btn.clicked.connect(self.start_timer)
        self.ui.stop_Btn.clicked.connect(self.stop_timer)
        self.ui.clr_Btn.clicked.connect(self.clr_timer)
        
        self.timer = QTimer()
        self.timer.timeout.connect(self.timerSlot)
        
        
        self.n = 0
        self.ui.lcdNumber.display(self.n)
        
    
    def start_timer(self):
        if self.timer.isActive() == False:
            self.timer.start(1000)
        
    def stop_timer(self):
        if self.timer.isActive() == True:
            self.timer.stop()
        
    def clr_timer(self):
        self.timer.stop()
        self.n = 0
        self.ui.time_Lcd.display(self.n)
        
    def timerSlot(self):
        self.n += 1
        self.ui.lcdNumber.display(self.n)
        
# 作为主函数才会执行
if __name__ == '__main__':
    
    # 创建应用程序
    app = QApplication(sys.argv)

    # 创建窗口
    w = MyWidget()
    
    #显示窗口
    w.show()

    #等待窗口停止
    sys.exit(app.exec())